<template>
	<view>
		<view class="login">
			<image class="login-img" src="../../static/logo.png" mode=""></image>
		</view>
		<view class="login-con">
			<view class="login-padd">
				<view class="login-account">
					<input class="uni-input" type="text" v-model="loginInfo.userName" placeholder="请输入账户" />
				</view>
				<view class="login-account">
					<input class="uni-input" @confirm="loginFlag" password type="text" v-model="loginInfo.password" placeholder="请输入密码" />
				</view>
			</view>
			<view class="inven-return-con" @tap="loginFlag">
				<view class="inven-return">
					<view class="return">登录</view>
				</view>
			</view>
		</view>
		<view class="login-text">
			<text class="login-text-color">登录即表示同意</text>
			<text class="login-text-color">《金医卫服务与隐私协议》</text>
		</view>
	</view>
</template>

<script>
	let _this
	export default {
		data() {
			return {
				loginInfo: {
					userName: '',
					password: '',
				}
			};
		},
		onLoad() {
			_this = this
		},
		onShow() {
			_this = this
		},
		methods: {
			loginFlag() {
				if (this.$validate.isNull(this.loginInfo.userName) || this.$validate.isNull(this.loginInfo.password)) {
					uni.showModal({
						content: '请输入帐号，密码',
						showCancel: false
					});
					return
				}
				plus.sqlite.selectSql({
					name: 'first',
					sql: "select * from userInfo where username = '" + this.loginInfo.userName + "' and password = '" + this.loginInfo
						.password + "'",
					success: function(data) {
						console.log('_this: ' + _this);
						if (_this.$validate.isNull(data) || data.length <= 0) {
							uni.showModal({
								content: '用户不存在',
								showCancel: false
							});
							return
						}
						_this.GoLogin()
						console.log('select userInfo success: ');
					},
					fail: function(e) {
						console.log('select userInfo failed: ' + JSON.stringify(e));
						uni.showModal({
							content: '用户不存在',
							showCancel: false
						});
					}
				});
			},
			// 登录
			GoLogin() {
				_this.$simpleCache.put("loginInfo", this.loginInfo, 60 * 60 * 8)
				uni.switchTab({
					url: '/pages/index/index'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login {
		width: 100%;
		height: 600rpx;
		line-height: 700rpx;
		background-color: #00A2DE;
		text-align: center;

		.login-img {
			width: 73px;
			height: 73px;
		}
	}

	.login-con {
		min-height: 530rpx;
		border-radius: 10px;
		background-color: #fff;
		box-shadow: 0 0 10px 1px #ccc;
		position: absolute;
		top: 450rpx;
		left: 26rpx;
		right: 26rpx;

		.login-padd {
			padding: 40rpx 30rpx;

			.login-account {
				padding: 30rpx;
				font-size: 14px;
				border-bottom: 1px solid #d7d7c9;
			}
		}

		// 按钮
		.inven-return-con {
			background-color: #FFFFFF;

			.inven-return {
				height: 90rpx;
				line-height: 90rpx;
				padding: 30rpx 24rpx;

				.return {
					text-align: center;
					color: #fff;
					border-radius: 50px;
					background-color: #00A2DE;
				}
			}
		}
	}

	.login-text {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 10px;
		font-size: 12px;
		text-align: center;

		.login-text-color:first-child {
			color: #ccc;
		}

		.login-text-color:last-child {
			color: #00A2DE;
		}
	}
</style>
